from selenium import webdriver
from time import sleep


def taobao(username, password):

    wd = webdriver.Chrome(r"F:\chromedriver_win32\chromedriver.exe")
    wd.get(
        r"https://login.taobao.com/member/login.jhtml?redirectURL=http%3A%2F%2Fcart.taobao.com%2Fcart.htm%3Fspm%3Da211oj.20948821.1997525049.1.d6c4YxMGYxMGSj%26from%3Dmini%26pm_id%3D1501036000a02c5c3739")
    sleep(1)
    element =wd.find_element_by_css_selector(r"input#fm-login-id")
    element.send_keys(username)
    element=wd.find_element_by_css_selector(r"input#fm-login-password")
    element.send_keys(password)
    wd.find_element_by_css_selector(r"button[type]").click()
    sleep(15)
    wd.find_element_by_css_selector(r"a#mc-menu-hd").click()
    i=1
    sleep(0.5)
    try:

        wd.find_element_by_css_selector(r'label[for="J_SelectAllCbx1"]').click()
    except:
        sleep(0.2)
        i=i+1
        print(i)
        wd.find_element_by_css_selector(r'label[for="J_SelectAllCbx1"]').click()
    sleep(0.2)
    try:
        wd.find_element_by_css_selector(r'a#J_Go').click()
    except:
        wd.find_element_by_css_selector(r'a#J_Go').click()
    try:
        wd.find_element_by_css_selector(r'a[class="go-btn"]').click()
    except:
        wd.find_element_by_css_selector(r'a[class="go-btn"]').click()
    wd.quit()

taobao('chn123698741','chn123456789')